package com.ruijiang.controller.task_service;


import com.ruijiang.controller.ApiPrefix;
import com.ruijiang.dto.count.VMTaskCountDto;
import com.ruijiang.dto.count.UserWorkCountDto;
import com.ruijiang.dto.insert.TaskInsertDto;
import com.ruijiang.dto.page.PageTaskDto;
import com.ruijiang.entity.Task;
import com.ruijiang.entity.TaskStatus;
import com.ruijiang.result.PageResult;
import com.ruijiang.service.TaskService.TaskService;
import com.ruijiang.service.TaskService.TaskStatusService;
import com.ruijiang.vo.task.CollectReportVO;
import com.ruijiang.vo.task.TaskInfoVO;
import com.ruijiang.vo.task.TaskReportInfoVO;
import com.ruijiang.vo.task.UserWorkCountVO;
import com.ruijiang.vo.user.UserTaskCountVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(ApiPrefix.TASK_SERVICE+"/task")
@Slf4j
public class TaskController {


    @Autowired
    private TaskService taskService;
    @Autowired
    private TaskStatusService taskStatusService;
    /**
     * 搜索工单
     *
     * @param dto
     * @return
     */
    @GetMapping("/search")
    public PageResult getPageList(PageTaskDto dto) {
        return taskService.getPageList(dto);
    }


    @PostMapping("/create")
    public Boolean InsertTask(@RequestBody TaskInsertDto dto){
        log.info("创建工单 {}",dto);
        return taskService.saveTask(dto);
    }


    @GetMapping("/allTaskStatus")
    public List<TaskStatus> getAllTaskStatus(){
        log.info("获取全部工单状态 ");
        return taskStatusService.list();

    }


    @GetMapping("/taskInfo/{taskId}")
    public TaskInfoVO getTaskInfoById(@PathVariable String taskId){
        log.info("查询工单详情 id={}",taskId);
        return taskService.getTaskInfoById(taskId);
    }


    @PostMapping("/cancel/{taskId}")
    public Boolean cancelTask(@PathVariable String taskId,@RequestBody Task task){
        taskService.cancelTask(taskId,task);
        return true;
    }

    /**
     * 获取补货警戒值
     * @return
     */
    @GetMapping("/supplyAlertValue")
    public Integer getSupplyAlertValue( Map<String,Integer> map){
        log.info("获取补货警戒值{}",map);
        return 20;
    }

    @GetMapping("/taskReportInfo/{start}/{end}")
    public List<TaskReportInfoVO> getTaskReportInfo(
            @PathVariable
            //@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
            String start,
            @PathVariable
            //@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
            String end
    ){
       return taskService.getTaskReportInfo(start,end);

    }


    @GetMapping("/collectReport/{start}/{end}")
    public List<CollectReportVO> CollectReport(
            @PathVariable
            //@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
            String start,
            @PathVariable
            //@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
            String end
    ){
        return taskService.CollectReport(start,end);
    }


    @GetMapping("/userWorkTop10/{start}/{end}/{isRepair}/{regionId}")
    public List<UserWorkCountVO> getUserWorkTop10(
            @PathVariable String start,
            @PathVariable String end,
            @PathVariable Boolean isRepair,
            @PathVariable String regionId
    ){
        log.info("获取人员排名,{},{},{},{}",start,end,isRepair,regionId);
        return taskService.getUserWorkTop10(start,end,isRepair,regionId);

    }



    @GetMapping("/userWork")
    public UserTaskCountVO getUserWork(UserWorkCountDto dto){
        log.info("获取人员工作量{}",dto);
        return  taskService.getUserWork(dto);
    }

    @GetMapping("/supplyCount/{innerCode}/{start}/{end}")
    public Integer getVMSupplyCount(
            @PathVariable String innerCode,
            @PathVariable String start,
            @PathVariable String end,
            VMTaskCountDto dto
            ){
        log.info("获取售货机补货次数");
        return taskService.getVMSupplyCount(innerCode,start,end,dto);
    }

    @GetMapping("/repairCount/{innerCode}/{start}/{end}")
    public Integer getVMRepairCount(
            @PathVariable String innerCode,
            @PathVariable String start,
            @PathVariable String end,
            VMTaskCountDto dto
    ){
        log.info("获取售货机补货次数");
        return taskService.getVMRepairCount(innerCode,start,end,dto);
    }

}
